/*
 * MsgForm.java
 *
 * Created on May 15, 2008, 2:10 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package morseme;

/**
 *
 * @author tt
 */
import javax.microedition.lcdui.*;

import java.util.*;

public class MsgForm extends Form implements CommandListener{

private static final Command backCmd = new Command("Back", Command.BACK, 1);
private static final Command playCmd = new Command("Play", Command.OK, 1);
private Inbox inbox;
private String morse;

public MsgForm(Inbox inbox){

super("Message Detail");
this.inbox = inbox;
this.addCommand(backCmd);
this.addCommand(playCmd);
this.setCommandListener(this);
}

public void setMessage(String addr, Date date, String msg){

String org = msg;
morse = MorseProcess.translate(org);
this.deleteAll();
// for(int i = 0; i < this.size(); i++){
// this.delete(i);
// }
this.append(new StringItem("From : ", formAddress(addr)));
this.append(new StringItem("Time : ", date.toString()));
this.append(new StringItem("+SMS : ", org));
this.append(new StringItem("+Morse : ", morse));
}

private String formAddress(String addr){
return addr;
}

public void commandAction(Command c, Displayable d){
if(c == backCmd){

this.inbox.updateInbox();
Display.getDisplay(MorseME.getMIDlet()).setCurrent(this.inbox);

}else if(c == playCmd){

if(morse != null){
MorseME.play(morse);
}
}
}
}

